橋本 Hashimoto   Baku

橋本 Hashimoto   Baku

Glisp v2: Why strong type? (Scratchpad)

This page is a personal scratchpad.
  • Type can be a hint to display an AST with an appropriate GUI
    • e.g. The min/max of numeric slider, label colors and icons for parameters
  • プロジェクトファイルとしてのGlispプログラムの一部が(型の不一致や実行時エラーなどによって)不正となったとき、その式の型推論に応じて「それらしい」デフォルト値を代わりに返すことによって、プロジェクト全体への影響を最小限とする

Unlike conventional language, the types in Glisp is more like a metadata that stores informations for GUI.
通常のプログラミング言語の「型」と異なり、Glispの型はメタデータとしての性質が強い。メモリ空間上に配置されたそのデータが意味論的に何なのかという従来の意味に加えて、デフォルト値・GUIとして表示された際のツールチップの説明文といった、付加情報も含めて「型」として扱う。

JavaScriptを例を挙げると以下のとおり。JSDocや引数のデフォルト値として扱われるような情報は、Glispにおいてはすべて「型情報」として扱われる。

/**
* Calculates a square of input
* @param {number} x - The input number
**/
function (x = 0) {
  return x * x;
}
^{doc: "Calculates a square of input"}
(=> [x: ^{default: 0 doc: "The Input number"}
                  Number]
    (* x x))